package com.nestease.qa.dao.api

import com.nestease.qa.dao.entity.Team
import com.sun.org.apache.xpath.internal.operations.Bool
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update

/**
 * @author zoudongdong
 * @date 2018/2/14
 */
interface TeamDAO {
    @Insert("""
            INSERT INTO `LG_team` (`teamId`, `teamName`, `creator`,`lastEditor`,`status`)
            VALUES (#{teamId},#{teamName}, #{creator},#{lastEditor},#{status})
            """)
    public void addTeam(Team team);

    @Select("""
            SELECT *
            FROM LG_team
            WHERE status=#{status}
            order by teamId asc
            """)
    public List<Team> getALLTeamList(@Param("status")int status);

    @Select("""
            SELECT ifnull(max(teamId),0)
            FROM LG_team;
            """)
    public int getMaxTeamId();

    @Update("""
            update LG_team
            set teamName=#{teamName},lastEditor=#{lastEditor}
            where teamId=#{teamId}
            """)
    public void editTeam(Team team);

    @Select("""
            select *
            from LG_team
            where teamId=#{teamId}
            """)
    public Team getTeamDetail(int teamId);

    @Select("""
            select teamId
            from LG_team
            where status=1
            """)
    public List<Integer> getTeamIdList();

    @Update("""
            update LG_team
            set status=0,lastEditor=#{lastEditor}
            where teamId=#{teamId}
            """)
    public void deleteTeam(Team team);

    @Select("""
            select count(*)
            from LG_team
            where teamName=#{teamName}
            and status=1
            """)
    public int getTeamByName(String teamName);
}
